package com.ly.web.controller.erp;

import java.util.List;

import com.ly.common.constant.HttpStatus;
import com.ly.heart.service.IKingDocTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.heart.domain.KingDocTypeEntity;
import com.ly.common.utils.poi.ExcelUtil;
import com.ly.common.core.page.TableDataInfo;

import javax.annotation.Resource;

/**
 * 金蝶-财务模块-单据类型Controller
 * @author wutao
 * @date 2024-06-24
 */
@Api (value = "KingDocType", tags = "金蝶-财务模块-单据类型")
@RestController
@RequestMapping ("/heart/KingDocType")
@Slf4j
public class KingDocTypeController extends BaseController {

    @Resource
    private IKingDocTypeService kingDocTypeEntityService;

    /**
     * 查询金蝶-财务模块-单据类型列表
     */
    //@PreAuthorize ("@ss.hasPermi('heart:KingDocType:list')")
    @GetMapping ("/list")
    @ApiOperation ("查询左侧树结构")
    public TableDataInfo list (KingDocTypeEntity kingDocTypeEntity) {
        List<KingDocTypeEntity> list = kingDocTypeEntityService.selectKingDocTypeEntityList ( kingDocTypeEntity );
        return getDataTable ( list );
    }

    /**
     * 查询金蝶-财务模块-单据类型列表
     */
    //@PreAuthorize ( "@ss.hasPermi('heart:KingDocType:list')" )
    @GetMapping ("/queryTable")
    @ApiOperation ("通过左侧树二、三级查询子Table数据")
    public TableDataInfo queryTable (KingDocTypeEntity kingDocTypeEntity) {
        List<KingDocTypeEntity> kingDocTypeEntities = kingDocTypeEntityService.queryTable ( kingDocTypeEntity );
        TableDataInfo tableDataInfo = new TableDataInfo ();
        tableDataInfo.setRows ( kingDocTypeEntities );
        tableDataInfo.setTotal ( kingDocTypeEntityService.queryCount ( kingDocTypeEntity ) );
        tableDataInfo.setCode ( HttpStatus.SUCCESS );
        return tableDataInfo;
    }

    /**
     * 通过点击单据的docCode查询所有子列表
     * @param kingDocTypeEntity
     * @return
     */
//    @GetMapping ("/queryChild")
//    @ApiOperation ("通过点击单据的docCode查询所有子列表")
//    public TableDataInfo queryChild (KingDocTypeEntity kingDocTypeEntity) {
//        startPage ();
//        List<KingDocTypeEntity> kingDocTypeEntities = kingDocTypeEntityService.queryChild ( kingDocTypeEntity );
//        return getDataTable ( kingDocTypeEntities );
//    }

    /**
     * 导出金蝶-财务模块-单据类型列表
     */
    @PreAuthorize ("@ss.hasPermi('heart:KingDocType:export')")
    @Log (title = "金蝶-财务模块-单据类型", businessType = BusinessType.EXPORT)
    @GetMapping ("/export")
    @ApiOperation ("导出金蝶-财务模块-单据类型列表")
    public AjaxResult export (KingDocTypeEntity kingDocTypeEntity) {
        List<KingDocTypeEntity> list = kingDocTypeEntityService.selectKingDocTypeEntityList ( kingDocTypeEntity );
        ExcelUtil<KingDocTypeEntity> util = new ExcelUtil<KingDocTypeEntity> ( KingDocTypeEntity.class );
        return util.exportExcel ( list, "info" );
    }

    /**
     * 获取金蝶-财务模块-单据类型详细信息
     */
    @PreAuthorize ("@ss.hasPermi('heart:KingDocType:query')")
    @GetMapping (value = "/{id}")
    @ApiOperation ("获取金蝶-财务模块-单据类型详细信息")
    public AjaxResult getInfo (@PathVariable ("id") String id) {
        return AjaxResult.success ( kingDocTypeEntityService.selectKingDocTypeEntityById ( id ) );
    }

    /**
     * 新增金蝶-财务模块-单据类型
     */
//    @PreAuthorize ("@ss.hasPermi('heart:KingDocType:add')")
    @Log (title = "金蝶-财务模块-单据类型", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation ("新增金蝶-财务模块-单据类型")
    public AjaxResult add (@RequestBody KingDocTypeEntity kingDocTypeEntity) {
        return kingDocTypeEntityService.insertKingDocTypeEntity ( kingDocTypeEntity );
    }

    /**
     * 修改金蝶-财务模块-单据类型
     */
    @PreAuthorize ("@ss.hasPermi('heart:KingDocType:edit')")
    @Log (title = "金蝶-财务模块-单据类型", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation ("修改金蝶-财务模块-单据类型")
    public AjaxResult edit (@RequestBody KingDocTypeEntity kingDocTypeEntity) {
        return kingDocTypeEntityService.updateKingDocTypeEntity ( kingDocTypeEntity );
    }

    /**
     * 删除金蝶-财务模块-单据类型
     */
    @PreAuthorize ("@ss.hasPermi('heart:KingDocType:remove')")
    @Log (title = "金蝶-财务模块-单据类型", businessType = BusinessType.DELETE)
    @DeleteMapping ("/{ids}")
    @ApiOperation ("删除金蝶-财务模块-单据类型")
    public AjaxResult remove (@PathVariable String[] ids) {
        return kingDocTypeEntityService.deleteKingDocTypeEntityByIds ( ids );
    }

    @Log (title = "禁用金蝶-财务模块-单据类型", businessType = BusinessType.DELETE)
    @RequestMapping ("disabled")
    @ApiOperation ("删除金蝶-财务模块-单据类型")
    public AjaxResult disabled (String id) {
        return kingDocTypeEntityService.disabled ( id );
    }
}
